<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CategoryDAO
 *
 * @author Hoang Thanh Duc
 */
class CategoryDAO {

    function getCategory($id){
        $category = new Category();
        $row = $category->fetchRow("id = $id and status =".Constant::$STATUS_AVAILABLE);
        return $row;
    }

    function getCategoryList(){
       $category = new Category();
       $row = $category->fetchAll($category->select()->where('status = ?',Constant::$STATUS_AVAILABLE));
       return $row;
    }

    function searchCategory($name){
        $category = new Category();
        $row = $category->fetchAll("status =".Constant::$STATUS_AVAILABLE." and name LIKE '%$name%'");
        return $row;
    }

    function addCategory($data){
        $category = new Category();

        $category->insert($data);
    }

    function editCategory($array){
    	$category = new Category();
        $where = $category->getAdapter()->quoteInto('id = ?', $array['id']);
        $category->update($array,$where);
    }

    function deleteCategory($id){
        $category = new Category();
        $data = array('status'=>Constant::$STATUS_DELETED);
        $where = $category->getAdapter()->quoteInto('id = ?', $id);
        $category->update($data, $where);
    }
}
?>